﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SAS.Toolkit;
using System.Text;

public partial class flash_xml : basePage
{
    /// <summary>
    /// 每个成员的成果列表
    /// </summary>
    protected List<TeamWorkInfos> tList = new List<TeamWorkInfos>();
    protected void Page_Load(object sender, EventArgs e)
    {
        MemberInfo[] mList = GetCacheMembers(1);
        System.Text.StringBuilder xmlnode = new System.Text.StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>");

        if (mList == null)
        {
            xmlnode.Append("<data><error>信息读取错误！请您与管理员联系！</error></data>");
            ResponseXML(xmlnode);
            return;
        }
        xmlnode.Append("<persons>");
        if (mList != null)
        {
            foreach (MemberInfo mi in mList)
            {
                xmlnode.Append("<person>");
                xmlnode.AppendFormat("<name>{0}</name>",mi.Nickname);
                if (minfo.Light >= 0 && minfo.Light < 2)
                {
                    xmlnode.AppendFormat("<qq>{0}</qq>", "星光点点");
                }
                else if (minfo.Light >= 2 && minfo.Light < 5)
                {
                    xmlnode.AppendFormat("<qq>{0}</qq>", "星光闪闪");
                }
                else if (minfo.Light >= 5 && minfo.Light < 9)
                {
                    xmlnode.AppendFormat("<qq>{0}</qq>", "星光灿烂");
                }
                else
                {
                    xmlnode.AppendFormat("<qq>{0}</qq>", "星光璀璨");
                }

                xmlnode.AppendFormat("<email>{0}</email>", mi.TeamAge);
                xmlnode.AppendFormat("<pub url=\"{0}\"></pub>", mi.Img);
                xmlnode.AppendFormat("<information>{0}</information>", mi.Selfdesc);
                xmlnode.Append("<pics>");

                tList = GetCacheWorkListByusername(mi.Name);
                foreach (TeamWorkInfos tw in tList)
                {
                    xmlnode.AppendFormat("<pic url=\"{0}\" linkurl=\"{1}\"></pic>", tw.Listpic, tw.Url);
                }
                xmlnode.Append("</pics>");
                xmlnode.AppendFormat("<ziduan1>{0}</ziduan1>", "星光亮度");
                xmlnode.AppendFormat("<ziduan2>{0}</ziduan2>", "星年龄");
                xmlnode.Append("</person>");
            }
        }
        xmlnode.Append("</persons>");

        ResponseXML(xmlnode);
    }

    private void ResponseXML(StringBuilder xmlnode)
    {
        System.Web.HttpContext.Current.Response.Clear();
        System.Web.HttpContext.Current.Response.ContentType = "Text/XML";
        System.Web.HttpContext.Current.Response.Expires = 0;
        System.Web.HttpContext.Current.Response.Cache.SetNoStore();
        System.Web.HttpContext.Current.Response.Write(xmlnode.ToString());
        System.Web.HttpContext.Current.Response.End();
    }

    #region 根据成员名获取成果列表
    /// <summary>
    /// 根据成员名获取成果列表
    /// </summary>
    /// <param name="userName"></param>
    /// <returns></returns>
    protected List<TeamWorkInfos> GetCacheWorkListByusername(string username)
    {
        List<TeamWorkInfos> mlist = new List<TeamWorkInfos>();
        mlist.AddRange(GetCacheTeamWorkInfos(1));
        //委托
        Predicate<TeamWorkInfos> mpush = new Predicate<TeamWorkInfos>(delegate(TeamWorkInfos work) { return work.Members.Contains(username); });
        mlist = mlist.FindAll(mpush);
        return mlist;
    }
    #endregion
}
